<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes">
    <title>登录 - Web邮箱</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
    <link rel="shortcut icon" href="favicon.png" type="image/x-icon">
</head>
<body>
    <div id="login-page" class="auth-container">
        <div class="auth-form">
            <h2>用户登录</h2>
            <form class="layui-form" id="login-form">
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="text" name="username" required lay-verify="required" class="layui-input" placeholder=" " title="3-50字符">
                        <label class="form-label">用户名</label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="password" name="password" required lay-verify="required" class="layui-input" placeholder=" " title="8位以上">
                        <label class="form-label">密码</label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="text" name="mfa_token" class="layui-input" placeholder=" " maxlength="6" title="6位数字">
                        <label class="form-label">MFA代码 (选填)</label>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block auth-buttons">
                        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登录</button>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-top: 10px;">
                    <div class="layui-input-block" style="text-align: center;">
                        <div style="margin-bottom: 10px; color: #999; font-size: 12px;">
                            <i class="layui-icon layui-icon-tips"></i> 使用硬件密钥可免输用户名和密码
                        </div>
                        <button type="button" class="layui-btn layui-btn-normal layui-btn-fluid" id="webauthn-login-btn">
                            <i class="layui-icon layui-icon-usb"></i> 硬件密钥登录
                        </button>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-top: 15px;">
                    <div class="layui-input-block" style="text-align: center;">
                        <a href="register.html" class="layui-btn layui-btn-primary layui-btn-fluid">注册新账户</a>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <script src="layui/layui.js"></script>
    <script src="js/common.js"></script>
    <script src="js/api.js"></script>
    <script src="js/auth.js"></script>
    <script>
        // 页面加载时检查token
        document.addEventListener('DOMContentLoaded', function() {
            AuthModule.checkTokenAndRedirect();
        });

        layui.use(['form', 'layer'], function(){
            var form = layui.form;
            var layer = layui.layer;

            // 监听登录提交
            form.on('submit(login)', function(data){
                AuthModule.handleLogin(data.field);
                return false;
            });
        });
    </script>
</body>
</html>
